package org.ffmpeg.ohos.filters;

import java.io.File;
import java.io.IOException;

public class DrawTextVideoFilter extends VideoFilter {

	private String mX;
	private String mY;
	private String mText;
	private String mFontColor;
	private int mFontSize;
	private File mFileFont;
	private int mBox;
	private String mBoxColor;

	public final static String X_CENTERED = "(w-text_w)/2";
	public final static String Y_CENTERED = "(h-text_h-line_h)/2";

	public final static String X_LEFT = "0";
	public final static String Y_BOTTOM = "(h-text_h-line_h)";

	public DrawTextVideoFilter (String text)
	{
		mX = X_CENTERED;
		mY = Y_CENTERED;

		mText = text;
		mFontColor = "white";
		mFontSize = 36;
		mFileFont = new File("/system/fonts/Roboto-Regular.ttf");
    	if (!mFileFont.exists())
    		mFileFont = new File("/system/fonts/DroidSerif-Regular.ttf");

    	mBox = 1;
    	mBoxColor = "black@0.5";//0x00000000@1

	}

	public DrawTextVideoFilter (String text, String x, String y, String fontColor, int fontSize, File fontFile, boolean showBox, String boxColor, String boxOpacity)
	{
		mX = x;
		mY = y;

		mText = text;
		mFontColor = fontColor;
		mFontSize = fontSize;

		mFileFont = fontFile;

    	mBox = showBox? 1 : 0;
    	mBoxColor = boxColor + '@' + boxOpacity;

	}

	@Override
	public String getFilterString() throws IOException {

		StringBuffer result = new StringBuffer ();
		result.append("drawtext=");
		result.append("fontfile='").append(mFileFont.getCanonicalPath()).append("':");
		result.append("text='").append(mText).append("':");
		result.append("x=").append(mX).append(":");
		result.append("y=").append(mY).append(":");
		result.append("fontcolor=").append(mFontColor).append(":");
		result.append("fontsize=").append(mFontSize).append(":");
		result.append("box=").append(mBox).append(":");
		result.append("boxcolor=").append(mBoxColor);

		return result.toString();
	}
}